package com.amado.course35Concurrent;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * ArrayList 非线程安全的
 * Vector 线程安全
 * CopyOnWriteArrayList 线程安全 取值时不用加锁
 */
public class S05VectorArrayList {
    public static void main(String[] args) {
    	List<String> list =new ArrayList<>();
    	List<String> vector =new Vector<>();
    	//get方法添加synchronized实现线程安全
    	vector.get(0);
    	vector.add("0");
    	List<String> copyOnWriteArrayList = new CopyOnWriteArrayList<>();
    	//get时没有限制访问
    	copyOnWriteArrayList.get(1);
    	//添加时copy一个新的数组
    	copyOnWriteArrayList.add("a");
    }
    
}
